﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using DTO;

namespace DAO
{
    public class KHACHHANGDAO
    {
        public DataTable GET_KHACHHANG()
        {
            DataTable dt = new DataTable();
            SqlConnection cn = Connection.ConnectionData();
            SqlCommand cmd = new SqlCommand("GET_KHACHHANG", cn);
            cmd.CommandType = CommandType.StoredProcedure;
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            da.Fill(dt);
            cn.Close();
            return dt;
        }

        public void THEM_KHACHHANG(KHACHHANGDTO kh)
        {
            SqlConnection cn = Connection.ConnectionData();
            SqlCommand cmd = new SqlCommand("THEM_KHACHHANG", cn);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add("@tenkh", SqlDbType.NVarChar);
            cmd.Parameters.Add("@sdtkh", SqlDbType.Char);
            cmd.Parameters.Add("@diemtichluy", SqlDbType.Int);

            cmd.Parameters["@tenkh"].Value = kh.TenKH;
            cmd.Parameters["@sdtkh"].Value = kh.SDTKH;
            cmd.Parameters["@diemtichluy"].Value = kh.DiemTichKuy;

            cmd.ExecuteNonQuery();
            cn.Close();
        }

        public void CAPNHAT_KHACHHANG(KHACHHANGDTO kh)
        {

            SqlConnection cn = Connection.ConnectionData();
            SqlCommand cmd = new SqlCommand("CAPNHAT_KHACHHANG", cn);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add("@makh", SqlDbType.Int);
            cmd.Parameters.Add("@tenkh", SqlDbType.NVarChar);
            cmd.Parameters.Add("@sdtkh", SqlDbType.Char);
            cmd.Parameters.Add("@diemtichluy", SqlDbType.Int);

            cmd.Parameters["@makh"].Value = kh.MaKH;
            cmd.Parameters["@tenkh"].Value = kh.TenKH;
            cmd.Parameters["@sdtkh"].Value = kh.SDTKH;
            cmd.Parameters["@diemtichluy"].Value = kh.DiemTichKuy;

            cmd.ExecuteNonQuery();
            cn.Close();
        }

        public void XOA_KHACHHANG(KHACHHANGDTO kh)
        {
            SqlConnection cn = Connection.ConnectionData();
            SqlCommand cmd = new SqlCommand("XOA_KHACHHANG", cn);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add("@makh", SqlDbType.Int);

            cmd.Parameters["@makh"].Value = kh.MaKH;

            cmd.ExecuteNonQuery();
            cn.Close();
        }
    }
}
